const { BrowserWindow, ipcMain, net } = require('electron')
const path = require('path')


let registerWindow

function createrRegisterWindow(mainWindow) {

    registerWindow = new BrowserWindow({
        parent: mainWindow,
        modal: true,
        autoHideMenuBar: true,
        resizable: false,
        height: 530,
        useContentSize: true,
        width: 350,
        // frame: false,
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
        }
    })

    registerWindow.loadFile(path.resolve(__dirname, "../../main/static/index.html"))
    registerWindow.on('closed', () => {
        registerWindow = null
    })

    ipcMain.on("request", function (e, url) {
        const request = net.request(url)
        request.on('response', (res) => {
            res.on("data", (chunk) => {
                // console.log(chunk.toString())
                e.returnValue = chunk.toString()
            })
        })
        request.end()
    })

}

module.exports = createrRegisterWindow